import unittest
import requests
import jsonschema


class TestIhrmLogin(unittest.TestCase):
    # 测试方法 登录成功
    def test01_login_success(self):
        # 组织url
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "13800000002", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登录成功：", resp.json())
        # 断言
        self.assertEqual(200, resp.status_code)
        # 使用全量字段加校验
        schema = {
            "type": "object",
            "properties": {
                "success": {"const": True},
                "code": {"const": 10000},
                "message": {"pattern": "操作成功"},
            },
            "required":["success","code","message"]
        }
        res=jsonschema.validate(instance=resp.json(),schema=schema)
        print(res)
        # self.assertEqual(True, resp.json().get("success"))
        # self.assertEqual(10000, resp.json().get("code"))
        # self.assertIn("操作成功", resp.json().get("message"))
